package com.qf.qfsyspringbootstarter.conf;

import com.qf.qfsyspringbootstarter.utils.QfFileAppender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

import java.io.IOException;

@Configuration
@ConditionalOnProperty(prefix = "qfsy",name = "filepath")
@EnableConfigurationProperties(QfsyProperties.class)
public class QfsyAutoConfiguration {

    @Autowired
    QfsyProperties qfsyProperties;

    @Bean
    @Scope("prototype")   // 该bean是多例模式
    public QfFileAppender qfFileAppender() throws IOException {

        final QfFileAppender qfFileAppender = new QfFileAppender(qfsyProperties.getFilepath());

        return qfFileAppender;

    }

}
